package main

import (
    "fmt"
    // "log"
    // "os"
    // "path/filepath"
    // "io/ioutil"
    "sync"
    "math/rand"
    "time"
)

var waitgroup sync.WaitGroup


func main() {
    Depthlen(4,4,16)

    // c := make(chan int, 10)
    

    for n:=0;n<0;n++{
        fmt.Println("-----start n:",n)
        out := make([]int, 10)
        r   := rand.New(rand.NewSource(time.Now().UnixNano()))
        for i:=0;i<10;i++{
            waitgroup.Add(1)
            go func(i int) {
                out[i] = r.Intn(100)
                fmt.Println("i:", i)
                waitgroup.Done()
            }(i)
        }

        // for i:=0;i<10;i++{
        //     <-c
        // }
        waitgroup.Wait() 
        fmt.Println(out)
        fmt.Println("-----end n:",n)
    }
    
    
    fmt.Println("all done!")
	
}


func Depthlen(depth uint32, maxdepth uint32, total int) int  {
    var len int

    if depth >= maxdepth{
        len = total - 1<<(maxdepth-1)
    }else{
        for i:=uint32(0);i<=maxdepth;i++{
            if depth == i{
                len = 1<<i
            }
        }
    }
    
    fmt.Println("depth len:", len)

    return len
}
